package com.java.huxb.day02;

import java.lang.reflect.Method;

/**
 * @author huxb
 * @date 2020/3/2 0002 下午 10:29
 */
class Apple{
    private String name;

    public Apple() {
    }

    public Apple(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Apple{" +
                "name='" + name + '\'' +
                '}';
    }
}
public class Test004 {
    public static void main(String[] args) throws  Exception {
        Class<?> appleClass = Class.forName("com.java.huxb.day02.Apple");
        Object appleObj = appleClass.newInstance(); // == new obj
        Method getName = appleClass.getMethod("getName");
        Method setName = appleClass.getMethod("setName", String.class);
        setName.invoke(appleObj, "小米"); // == 对象.setName()
        System.out.println(getName.invoke(appleObj));
        System.out.println(appleObj);

        Apple apple = new Apple();
        System.out.println(apple.getClass());
    }
}
